package org.bluedream.core.module.controller.emp;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.bluedream.comm.base.BaseController;
import org.bluedream.comm.utils.RestResult;
import org.bluedream.core.config.advice.RsaSecurityParameter;
import org.bluedream.core.module.entity.emp.Emp;
import org.bluedream.core.module.entity.goods.Goods;
import org.bluedream.core.module.service.depItem.DepItemService;
import org.bluedream.core.module.service.emp.EmpService;
import org.bluedream.core.utils.configUtil.GoalConfigUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @ClassName EmpController
 * @Description TODO
 * @Author Administrator
 * @Data 2022/7/20 10:57
 * @Version
 */
@Slf4j
@Controller
@RequestMapping(value = "${adminPath}/emp")
public class EmpController extends BaseController {
    @Resource
    private EmpService empService;
    @Resource
    private DepItemService depItemService;

    @ModelAttribute
    public Emp get(String id){
        return empService.getById(id);
    }

    @RequiresPermissions("emp:view")
    @RequestMapping(value = {"/list" , ""})
    public String list(Emp entity, Model model){
        model.addAttribute("pageSize" , GoalConfigUtil.getValueByKey("sys.page.size"));
        model.addAttribute("emp" , entity);
        return "module/emp/empList";
    }

    @RequiresPermissions("emp:edit")
    @RequestMapping("/form")
    public String form(Emp entity, Model model){
        model.addAttribute("emp" , entity);
        return "module/emp/empForm";
    }

    @RequiresPermissions("emp:view")
    @RequestMapping("/findPage")
    @ResponseBody
    public IPage<Emp> findPage(@RsaSecurityParameter Emp entity){
        return empService.findPage(entity);
    }

    @RequiresPermissions("emp:view")
    @RequestMapping("/depTreeData")
    @ResponseBody
    public List<Map<String , Object>> depTreeData(@RequestParam(defaultValue="1")String isShowCode , @RequestParam(defaultValue="undefined")String excludeCode){
        return depItemService.treeData(excludeCode , isShowCode);
    }

    @RequiresPermissions("emp:edit")
    @RequestMapping("/save")
    @ResponseBody
    public RestResult save(Emp entity){
        return empService.saveEntity(entity);
    }
}